public class MyQueue {

     class ListNode{
        public int val;
        public ListNode prev;
        public ListNode next;

        public ListNode(int val) {
            this.val = val;
        }
    }
    public ListNode first;
    public ListNode last;

    public void offer( int val){
        ListNode node =new ListNode(val);
        if (isEmpty()){
            first=last=node;
        }else {
            last.next=node;
            node.prev=last;
            last=node;
        }
    }

    public int poll(){
        if (isEmpty()){
            return -1;
        }else{
            int num=first.val;
            first=first.next;
            if (first==null) return num;
            first.prev=null;
            return num;
        }
    }

    public int peek(){
        if (isEmpty()) return -1;
        return first.val;
    }

    public boolean isEmpty(){
        if (first==null){
            return true;
        }else return false;
    }
}
